package com.xinke.module.system.mapper.user;

import java.util.*;

import com.xinke.component.common.pojo.PageResult;
import com.xinke.component.mybatis.mybatis.core.query.LambdaQueryWrapperExt;
import com.xinke.component.mybatis.mybatis.core.mapper.BaseMapperExt;
import com.xinke.module.system.model.entity.user.RoleDO;
import org.apache.ibatis.annotations.Mapper;
import com.xinke.module.system.model.vo.user.*;

/**
 * 角色信息 Mapper
 *
 * @author yzx
 */
@Mapper
public interface RoleMapper extends BaseMapperExt<RoleDO> {

    default PageResult<RoleDO> selectPage(RolePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperExt<RoleDO>()
                .likeIfPresent(RoleDO::getRoleName, reqVO.getRoleName())
                .eqIfPresent(RoleDO::getRoleCode, reqVO.getRoleCode())
                .eqIfPresent(RoleDO::getShowSort, reqVO.getShowSort())
                .eqIfPresent(RoleDO::getDataScope, reqVO.getDataScope())
                .eqIfPresent(RoleDO::getDataScopeDeptIds, reqVO.getDataScopeDeptIds())
                .eqIfPresent(RoleDO::getRoleStatus, reqVO.getRoleStatus())
                .eqIfPresent(RoleDO::getRoleType, reqVO.getRoleType())
                .eqIfPresent(RoleDO::getRemark, reqVO.getRemark())
                .orderByDesc(RoleDO::getRoleId));
    }

    default RoleDO selectByName(String name) {
        return selectOne(RoleDO::getRoleName, name);
    }

    default RoleDO selectByCode(String code) {
        return selectOne(RoleDO::getRoleCode, code);
    }
}